{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "Copyright(c) 2025 NVIDIA Corporation. All rights reserved.\n",
    "\n",
    "NVIDIA Corporation and its licensors retain all intellectual property\n",
    "and proprietary rights in and to this software, related documentation\n",
    "and any modifications thereto.Any use, reproduction, disclosure or\n",
    "distribution of this software and related documentation without an express\n",
    "license agreement from NVIDIA Corporation is strictly prohibited."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Customize Voice for the Digital human\n",
    "\n",
    "This notebook outlines the step-by-step process to modify the voice of the digital human. The notebook assumes that the TTS processor configured for the pipeline is elevenLabs. The steps outlined in this notebook are extendable to any other supported TTS processor though.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ensure that the Pre-requisites are met\n",
    "\n",
    "Please run through the steps noted in the setup prequisites notebook to ensure that you have the necessary setup in place.\n",
    "\n",
    "Check the status of the application again by running the following command. \n",
    "\n",
    "Note: You will need to select the python environment to run the notebook for the first time. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!kubectl get po -n app"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Download the ACE Controller Configuration\n",
    "* Ensure that the downloaded ACE Controller configuration is in sync. You can click on the download button again to download the latest version of the configuration. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![ACE Configurator](pictures/ace_configurator_sync.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Locate and Edit the `bot.py` File\n",
    "1. Navigate into the folder downloaded from the previous step (e.g., `ace-controller-ace-controller-deployment`), and locate the following directory path:\n",
    "\n",
    "```\n",
    "ace-controller-ace-controller-deployment -> assets -> app-storage-volume -> src\n",
    "```\n",
    "\n",
    "2. Open the file `bot.py` in your editor."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![Avatar Controller Config](pictures/ace_controller_bot.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Modify the voice id\n",
    "\n",
    "Locate the tts initialization section in `bot.py` file. Example snippet below. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tts = ElevenLabsTTSServiceWithEndOfSpeech(\n",
    "        api_key=os.getenv(\"ELEVENLABS_API_KEY\"),\n",
    "        voice_id=os.getenv(\"ELEVENLABS_VOICE_ID\", \"EXAVITQu4vr4xnSDxMaL\"),\n",
    "        sample_rate=16000,\n",
    "        model = \"eleven_flash_v2_5\",\n",
    "    )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Modify the voice id to any one of the IDs mentioned below - \n",
    "\n",
    "* 9BWtsMINqrJLrRacOk9x\n",
    "* cgSgspJ2msm6clMCkdW9\n",
    "* XrExE9yKIg1WjnnlVkGX \n",
    "\n",
    "Save the `bot.py` containing your changes.  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Upload the Changes\n",
    "Save your local changes in VSCode. \n",
    "In the ACE Configurator view in VSCode, click the **Upload** button to upload the modified `bot.py` file."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![Avatar Controller Upload Config](pictures/upload_config.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Ensure that the changes are finished updating. This might take a few seconds.\n",
    "\n",
    "Once the changes are successfully updated. the ACE Configurator view will show a green `Synced` symbol again for the app-storage-volume. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![Avatar Controller Upload Config](pictures/ace-configurator-synced.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Test Your Changes\n",
    "1. Open the browser UI where the digital human is hosted. (your current URL:30111)\n",
    "2. Refresh the page. (Note: you might need to refresh it a couple of times)\n",
    "3. Verify that the digital human converses with an updated voice."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Conclusion\n",
    "You have now successfully configured your digital human application to use a custom voice. 🎉"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
